#include("../layout.html")
#set(PATH='/core/attachment')
#@layout()

#define css()
<link href="#(CTX)/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
#end

#define js()
<!-- Bootstrap table -->
<script src="#(CTX)/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="#(CTX)/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="#(CTX)/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

<script>
  <!-- 页面js,请自行将js内容导出到js文件中 -->
  $(document).ready(function () {
    var _listUrl = _CTX_ + _PATH_ + '/list';
    var _batchDeteleUrl = _CTX_ + _PATH_ + '/batchDelete';

    $('#table').bootstrapTable({
      url: _listUrl,
      method: 'get',
      queryParams: function () {
        //每次查询时传入后台的查询条件
      },
      height: 450,
      pagination: true,
      pageNumber: 1,
      pageSize: 20,
      pageList: [20, 50, 100],
      clickToSelect: true,
      search: true,
      searchOnEnterKey: true,
      showRefresh: true,
      toolbar: '#toolbar',
      columns: [{
        checkbox: true
      }, {
        field: 'uuid',
        title: '主键',
        visible: false,
        searchable: false
      }, {
        field: 'filename',
        title: '文件名'
      }, {
        field: 'filePath',
        title: '存储位置'
      }, {
        field: 'mineType',
        title: '文件类型'
      }, {
        field: 'fileSize',
        title: '文件大小',
        formatter: function (value, row, index, field) {
          return value;
        }
      }, {
        title: '字段信息',
        formatter: function (value, row, index, field) {
          return row.entityName?(row.entityName + "(" + row.pkValue?row.pkValue:"未知主键" + ")的" + row.fieldName?row.fieldName:"未知" + "字段"):"未知对象";
        }
      }, {
        title: '操作',
        events: {
          "click .view": function (e, value, row, index) {
            alert("查看")
            return false;
          },
          "click .download": function (e, value, row, index) {
            alert("下载")
            return false;
          }
        },
        formatter: function (value, row, index, field) {
          return '<a href="#" class="view">查看</a>&nbsp;&nbsp;&nbsp;&nbsp;'
              + '<a href="#" class="download">下载</a>';
        }
      }]
    });

    $('#btnDelete').click(function () {
      var selections = $('#table').bootstrapTable('getSelections');
      if (selections) {
        var pkArray = [];
        for (var i in selections) {
          pkArray.push(selections[i].uuid);
        }
        $.ajax({
          url: _batchDeteleUrl,
          type: 'POST',
          data: $.param({"uuids": pkArray}, true),
          cache: false,
          dataType: 'json',
          success: function (ret) {
            if (ret.state == 'ok') {
              alert("删除成功");
              $('#table').bootstrapTable('refresh');
            } else {
              alert(ret.msg);
            }
          }
        });
      }
    });

    $('#table').bootstrapTable("resetView", {height: calcTableHeight($('#table'),450,30,80)});
    $(window).bind('resize', function () {
        $('#table').bootstrapTable("resetView", {height: calcTableHeight($('#table'),450,30,80)});
    });

  })
</script>
#end

#define content()
<div class="row">
  <div class="col-sm-12 col-lg-12">
    <div class="ibox float-e-margins nomargin">
      <div class="ibox-title">
        <h2>附件管理</h2>
      </div>
      <div class="ibox-content">
        <div class="row row-lg">
          <div class="col-sm-12">
            <!-- Example Rowstyle -->
            <div class="example-wrap margin-sm-0">
              <div class="example">
                <div id="toolbar" class="btn-group">
                  <button id="btnDelete" type="button" class="btn btn-primary">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
                  </button>
                </div>
                <table id="table">
                </table>
              </div>
            </div>
            <!-- End Example Rowstyle -->
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
#end